package org.vectrics.recruiter.web.tags;

import org.vectrics.common.html.*;
import org.vectrics.hibernate.ThreadProperties;
import org.apache.log4j.*;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.user.RecruitPersonSearcher;
import org.vectrics.recruiter.user.RecruitPersonSearchCriteria;
import org.vectrics.user.*;

import java.util.HashSet;
import java.util.Collection;
import java.util.Set;



public class SourceListTag extends org.vectrics.user.web.struts.UserGroupManagerTag {
	public static final long serialVersionUID = 15262793;
    static private Category log = Category.getInstance(SourceListTag.class);
    public static String TABLE_FONT = "subFont";
    public static String NO_ELEMENTS_MESSAGE = "No Sources Found";
    
    
    public SourceListTag() {
    	//
    }

    protected PersonSearcher getPersonSearcher() {
    	return(new RecruitPersonSearcher());
    }
    
	protected String getNewUserHref() {
		return(getContextPath() + "/hrs-public/admin/user/edit.do?newUser=true");	
	}
	
	protected boolean showNewUserLink() {
		return(true);
	}
	
	protected String getNoElementsMessage() {
		return(NO_ELEMENTS_MESSAGE);
	}

	protected Collection getUserPrivileges() {
		HashSet roles = new HashSet();
		roles.add("recruit-source");
		return(roles);
	}

	
	protected PersonSearchCriteria getUserCriteria() {
		RecruitPersonSearchCriteria criteria = new RecruitPersonSearchCriteria();
		Person authPerson = ThreadProperties.getPerson();
		Set domains = CoreServiceLocator.getPersonService()
			.findDomainsWithUserPrivilege(authPerson, Person.PRIVILEGE_PERSON_VIEW);
		criteria.setDomains(domains);
		criteria.setSourcesOnly(true);
		return(criteria);
	}
   
    protected void setTableProperties(BorderTable table) {
    	//
    }
    
    public String getDescription() {
        log.debug("getDescription() called.");
        return("Source List");
    }
    
    protected String getPageListLink() {
        return(getContextPath() + "/admin/candidate");
    }
    
    public void makeHeaderCells(Row row) {
        log.debug("makeHeaderCells() called.");
        
        Cell cell = row.addCell();
        cell.addElement(TextHelper.getFont("subFont", "<b>Last Name</b>"));

        cell = row.addCell();
        cell.addElement(TextHelper.getFont("subFont", "<b>First Name</b>"));

        cell = row.addCell();
        cell.addElement(TextHelper.getFont("subFont", "<b>User Name</b>"));

        cell = row.addCell();
        cell.addElement(TextHelper.getFont("subFont", "<b>Importance</b>"));

    }

    protected void makeObjectRow(Row row, Person user) {
        Cell cell = row.addCell();
        cell.addElement(TextHelper.getFont("subFont", user.getLastName()));

        cell = row.addCell();
        cell.addElement(TextHelper.getFont("subFont", user.getFirstName()));

        cell = row.addCell();
        cell.addElement(TextHelper.getFont("subFont", user.getName()));

        cell = row.addCell();
        /*
        RecruitSourceComponent sourceComponent = userManager.findSourceComponent(user);
        String importanceStr ="";
        for (int i = 0; i < sourceComponent.getImportance(); i++) {
            importanceStr+= "* ";
        }
        
        cell.addElement(TextHelper.getFont("subFont", importanceStr));
        */
		cell.addElement(TextHelper.getFont("subFont", "NOT IMPLEMENTED"));
    }
    
    

}
